<?php

namespace haibao\www\data;

class Activity extends \haibao\www\data\BaseMysql{

    public function __construct(){
        parent::__construct('\haibao\cms\model\data\activity\Activity');
    }
    
    public function addSearchKeywordNum($name){
    	if($name){
    		$sql = "update ActivityKeyword set SearchCount = SearchCount+1 where Name=%s and ShowTime='".date('Y-m-d',time())."'";
    		$this->query($sql,array($name));
    	}
    }
    
    public function checkPrize($activityId,$prizeId,$isGet){
    	if($isGet){
    		$updateActivitySql = "update Activity set RestPrizeNum = RestPrizeNum-1 where Id=%s";
    		$updatePrizeSql = "update ActivityPrize set RestNum = RestNum-1 where Id=%s";
    		$this->query($updateActivitySql,array($activityId));
    		$this->query($updatePrizeSql,array($prizeId));
    		return true;
    	}else{
    		$sql = "select Id from ActivityPrize where Id=%s and RestNum > 0 and Status=%s";
    		$res = $this->query($sql,array($prizeId,\haibao\www\model\data\activity\ActivityPrize::STATUS_ENABLE))->fetch_assoc();
    		if($res){
    			return true;
    		}
    	}
    	return false;
    }
}